import { useToast } from "@/hooks/use-toast"
import {
  Toast,
  ToastClose,
  ToastDescription,
  ToastProvider,
  ToastTitle,
  ToastViewport,
} from "@/components/ui/toast"

export function Toaster() {
  const { toasts } = useToast()

  return (
    <ToastProvider>
      {toasts.map(function ({ id, title, description, action, ...props }) {
        return (
          <Toast 
            key={id} 
            {...props}
            className="apple-glassmorphism rounded-2xl px-5 py-4 flex gap-3 data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-top-full data-[state=open]:slide-in-from-top-full border border-white/30"
          >
            <div className="grid gap-1.5">
              {title && (
                <ToastTitle className="text-base font-medium text-[#1d1d1f]">
                  {title}
                </ToastTitle>
              )}
              {description && (
                <ToastDescription className="text-sm text-[#86868b] opacity-90">
                  {description}
                </ToastDescription>
              )}
            </div>
            {action}
            <ToastClose className="h-7 w-7 rounded-full flex items-center justify-center bg-white/80 text-[#86868b] hover:text-[#1d1d1f] hover:bg-white transition-colors apple-shadow-sm absolute top-3 right-3" />
          </Toast>
        )
      })}
      <ToastViewport className="fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:top-4 sm:right-0 sm:flex-col md:max-w-[420px]" />
    </ToastProvider>
  )
}
